/// Coder: Jose Ricardo Mello Viana - 2008
/// Bugs? e-mail me: zezim.ricardo@gmail.com

/*
 * colorInterface.cpp
 *
 *  Created on: 07/09/2008
 *      Author: zezim
 */

#include "colorInterface.h"

ColorInterface::ColorInterface() {

}

ColorInterface::ColorInterface(double w, double h) {
   width = w;
   height = h;
   drawColorInterface = true;

   current = Color(1.0, 0.0, 0.0, 1.0);
   ymin = 143.0 * height / 800;
   qtde = 11;

   // colors definition
   colors.push_back(Color(1.0f, 0.0f, 0.0f, 1.0f));
   colors.push_back(Color(0.0f, 1.0f, 0.0f, 1.0f));
   colors.push_back(Color(0.0f, 0.0f, 1.0f, 1.0f));
   colors.push_back(Color(1.0f, 1.0f, 0.0f, 1.0f));
   colors.push_back(Color(1.0f, 0.0f, 1.0f, 1.0f));
   colors.push_back(Color(0.0f, 1.0f, 1.0f, 1.0f));
   colors.push_back(Color(0.7f, 0.0f, 0.0f, 1.0f));
   colors.push_back(Color(0.0f, 0.7f, 0.0f, 1.0f));
   colors.push_back(Color(0.0f, 0.0f, 0.7f, 1.0f));
   colors.push_back(Color(0.7f, 0.7f, 0.0f, 1.0f));
   colors.push_back(Color(0.7f, 0.0f, 0.7f, 1.0f));
   colors.push_back(Color(0.0f, 0.7f, 0.7f, 1.0f));
   colors.push_back(Color(0.5f, 0.0f, 0.0f, 1.0f));
   colors.push_back(Color(0.0f, 0.5f, 0.0f, 1.0f));
   colors.push_back(Color(0.0f, 0.0f, 0.5f, 1.0f));
   colors.push_back(Color(0.5f, 0.5f, 0.0f, 1.0f));
   colors.push_back(Color(0.5f, 0.0f, 0.5f, 1.0f));
   colors.push_back(Color(0.0f, 0.5f, 0.5f, 1.0f));
   colors.push_back(Color(1.0f, 1.0f, 1.0f, 1.0f));
   colors.push_back(Color(0.7f, 0.7f, 0.7f, 1.0f));
   colors.push_back(Color(0.5f, 0.5f, 0.5f, 1.0f));
   colors.push_back(Color(0.0f, 0.0f, 0.0f, 1.0f));
}


ColorInterface::~ColorInterface() {

}

Color ColorInterface::getColor(int x, int y) {
   Color c = current;
   if (x > 3 && x < 83 && y > ymin + (74 * height / 800) && y < height - ymin) {
      int p = 2 * ((y - (int) ymin - (int) (74 * height / 800)) / (int) (40 * height / 800));
      if (x > 45) p += 1;
      c = colors[p];
      current = c;
   }
   return c;
}

void ColorInterface::draw() {
   if (drawColorInterface) {
      glDisable(GL_DEPTH_TEST);
      glDisable(GL_LIGHTING);

      int qtde = 11;
      float prop1 = 72 * height / 800,
            prop2 = 40 * height / 800;

      glColor3f(0.2f, 0.2f, 0.2f);
      glBegin(GL_QUADS);
         glVertex3f(1.0f, ymin, 0.0);
         glVertex3f(1.0f, height - ymin, 0.0);
         glVertex3f(85.0f, height - ymin, 0.0);
         glVertex3f(85.0f, ymin, 0.0);
      glEnd();

//      glColor3f(current[0], current[1], current[2]);
//      glBegin(GL_QUADS);
//         glVertex3f(3.0f, ymin + 2.0f, 0.0);
//         glVertex3f(3.0f, ymin + 71.0f, 0.0);
//         glVertex3f(83.0f, ymin + 71.0f, 0.0);
//         glVertex3f(83.0f, ymin + 2.0f, 0.0);
//      glEnd();

      glColor3f(current[0], current[1], current[2]);
      glBegin(GL_QUADS);
         glVertex3f(3.0f, ymin + 2.0f, 0.0);
         glVertex3f(3.0f, ymin + prop1, 0.0);
         glVertex3f(83.0f, ymin + prop1, 0.0);
         glVertex3f(83.0f, ymin + 2.0f, 0.0);
      glEnd();

      for (int i = 0; i < qtde; i++) {
         glColor3f(colors[2*i][0], colors[2*i][1], colors[2*i][2]);
         glBegin(GL_QUADS);
            glVertex3f(3.0f, ymin + prop1 + 2 + i * prop2, 0.0);
            glVertex3f(3.0f, ymin + prop1 + prop2 + i * prop2, 0.0);
            glVertex3f(43.0f, ymin + prop1 + prop2 + i * prop2, 0.0);
            glVertex3f(43.0f, ymin + prop1 + 2 + i * prop2, 0.0);
         glEnd();

         glColor3f(colors[2*i + 1][0], colors[2*i + 1][1], colors[2*i + 1][2]);
         glBegin(GL_QUADS);
            glVertex3f(45.0f, ymin + prop1 + 2 + i * prop2, 0.0);
            glVertex3f(45.0f, ymin + prop1 + prop2 + i * prop2, 0.0);
            glVertex3f(83.0f, ymin + prop1 + prop2 + i * prop2, 0.0);
            glVertex3f(83.0f, ymin + prop1 + 2 + i * prop2, 0.0);
         glEnd();
      }

      glEnable(GL_DEPTH_TEST);
      glEnable(GL_LIGHTING);
   }
}
